<template>
  <el-table 
  :data="tableData" 
  border 
  style="width: 100%"
  lazy
  :load="load"
  :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
    <el-table-column prop="title" label="标题" width="180" align="center">
    </el-table-column>
    <el-table-column
      prop="address"
      label="视频地址"
      align="center"
    >
    </el-table-column>
    <el-table-column label="操作" align="center">
      <template #default="scope">
        <el-button @click="update(scope.row)" type="primary">修改</el-button>
        <el-button @click.prevent="deleteRow(scope.$index, tableData)" type="danger">移除</el-button>
      </template>
    </el-table-column>
  </el-table>
  <el-pagination
    style="float: right"
    background
    layout="total,prev, pager, next"
    @current-change="getPage"
    :total="listQuery.total"
  >
  </el-pagination>
  <!-- 添加/修改 -->
  <el-dialog title="添加/修改" width="500px" v-model="addOrUpdateVisible">
    <el-form :model="addForm">
      <el-form-item label="标题" label-width="80px">
        <el-input v-model="addForm.title" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="视频地址" label-width="80px">
        <el-input v-model="addForm.address" autocomplete="off"></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="addOrUpdateVisible = false">取 消</el-button>
        <el-button type="primary" @click="addOrUpdateVisible = false"
          >确 定</el-button
        >
      </span>
    </template>
  </el-dialog>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      listQuery: {
        params: "",
        current: 1,
        total: 100,
        size: 10,
      },
      addOrUpdateVisible: false,
      tableData: [],
    };
  },
  created() {
    this.getPage();
  },
  methods: {
    getPage() {
      axios.post("http://localhost:8090/videos", this.listQuery).then((res) => {
        this.tableData = res.data.data.video;
        this.listQuery.total = res.data.data.total;
      });
    },

    update(row) {
      console.log(1111111111111111111111111111);
      console.log(row);
      (this.title = "修改${row.title}"), (this.addForm = row);
      this.addOrUpdateVisible = true;
    },
    deleteRow(index, rows) {
        rows.splice(index, 1);
      },
  },
};
</script>